package com.itany.boot.nmms.util;

import com.itany.boot.nmms.exception.MD5Exception;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
    public static String md5(String s) throws MD5Exception {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] b = md.digest(s.getBytes());
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(b);
        } catch (NoSuchAlgorithmException e) {
            throw new MD5Exception("MD5加密出错:(");
        }
    }
}
